package springbook.model;


import lombok.Data;
import springbook.enums.ResultCodeEnum;
@Data
public class Result<T> {

    private ResultCodeEnum code;
    private String errorMessage;
    private T data;

    public static <T> Result<T> noLogin() {
        Result result = new Result();
        result.setCode(ResultCodeEnum.NOLOGIN);
        result.setErrorMessage("用户未登录");
        return result;
    }
    public static <T> Result<T> success(T data) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.SUCCESS);
        result.setErrorMessage("");
        result.setData(data);
        return result;
    }
    public static <T> Result fail(String errMsg) {
        Result result = new Result();
        result.setCode(ResultCodeEnum.FAIL);
        result.setErrorMessage(errMsg);
        result.setData(null);
        return result;
    }
}
